/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.st.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.st.entity.StCheckLog;
import com.jeesite.modules.st.service.StCheckLogService;

/**
 * 进料检验Controller
 *
 * @author HOHD
 * @version 2020-12-16
 */
@Controller
@RequestMapping(value = "${adminPath}/st/stCheckLog")
public class StCheckLogController extends BaseController {

    @Autowired
    private StCheckLogService stCheckLogService;

    /**
     * 获取数据
     */
    @ModelAttribute
    public StCheckLog get(String id, boolean isNewRecord) {
        return stCheckLogService.get(id, isNewRecord);
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("st:stCheckLog:view")
    @RequestMapping(value = {"list", ""})
    public String list(StCheckLog stCheckLog, Model model) {
        model.addAttribute("stCheckLog", stCheckLog);
        return "modules/st/stCheckLogList";
    }

    /**
     * 查询列表数据
     */
    @RequiresPermissions("st:stCheckLog:view")
    @RequestMapping(value = "listData")
    @ResponseBody
    public Page<StCheckLog> listData(StCheckLog stCheckLog, HttpServletRequest request, HttpServletResponse response) {
        stCheckLog.setPage(new Page<>(request, response));
        Page<StCheckLog> page = stCheckLogService.findPage(stCheckLog);
        return page;
    }

    /**
     * 查看编辑表单
     */
    @RequiresPermissions("st:stCheckLog:view")
    @RequestMapping(value = "form")
    public String form(StCheckLog stCheckLog, Model model) {
        model.addAttribute("stCheckLog", stCheckLog);
        return "modules/st/stCheckLogForm";
    }

    /**
     * 保存数据
     */
    @RequiresPermissions("st:stCheckLog:edit")
    @PostMapping(value = "save")
    @ResponseBody
    public String save(@Validated StCheckLog stCheckLog) {
        Integer checkState = stCheckLog.getCheckState();
        if (checkState == null || 1 == checkState) {
            return renderResult(Global.FALSE, text("请填写检验状态！"));
        }
        stCheckLogService.save(stCheckLog);
        return renderResult(Global.TRUE, text("保存进料检验成功！"));
    }

    /**
     * 删除数据
     */
    @RequiresPermissions("st:stCheckLog:edit")
    @RequestMapping(value = "delete")
    @ResponseBody
    public String delete(StCheckLog stCheckLog) {
        stCheckLogService.delete(stCheckLog);
        return renderResult(Global.TRUE, text("删除进料检验成功！"));
    }

}